package controllerActions;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import dao.MeinPortfolioDAO;

import beans.MeinPortfolio;

public class PortfolioActions {
	public void preparePortfolio(MeinPortfolioDAO mpDAO, HttpSession session, HttpServletRequest request){
		int portfolioIndex = Integer.parseInt(request.getParameter("indexCounter"));
		ArrayList<MeinPortfolio> meinPortfolioList = new ArrayList<MeinPortfolio>();

		try {
			meinPortfolioList = mpDAO.findPortfolio(Integer.valueOf(session.getValue("UserID").toString()));

		} catch (NumberFormatException | SQLException e) {
			e.printStackTrace();
		}

		MeinPortfolio meineAktie = meinPortfolioList.get(portfolioIndex);
		String kuerzel = meineAktie.getKuerzel();
		String name = meineAktie.getName();
		request.setAttribute("aktieKuerzel", kuerzel);
		request.setAttribute("aktieName", name);

		request.setAttribute("portfolioIndex", portfolioIndex);
		session.putValue("meinPortfolioList", meinPortfolioList);
		session.putValue("portfolioIndex", portfolioIndex);
	}
}
